%{
	#include "../xpression-model/Model.h"
%}

%union
{
	double value;
	void* exp;
}

%token <value> CONSTANT

%token PHI THETA

%token PLUS MINUS MULTIPLY DIVIDE
%token LN COS SIN LOG POW

%token LEFT_BRACKET RIGHT_BRACKET
%token SEPARATOR COMBINATION

%type <exp> expression

%left PLUS MINUS MULTIPLY DIVIDE
%right POW

%%

input:
	expression SEPARATOR deltas						{ setTreeBase($1); }
	;
	
deltas:
	// Phi & Theta StepCounts
	CONSTANT COMBINATION CONSTANT					{ setThetaStep($1); setPhiStep($3); }
	;

expression:
	// Operators 
	expression PLUS expression						{ $$ = createPlus($1, $3); }
	| expression MINUS expression					{ $$ = createMinus($1, $3); }
	| expression MULTIPLY expression				{ $$ = createMultiply($1, $3); }
	| expression DIVIDE expression					{ $$ = createDivide($1, $3); }
	| expression POW expression						{ $$ = createPow($1, $3); }
	
	// Brackets 
	| LEFT_BRACKET expression RIGHT_BRACKET			{ $$ = $2; }
	| LN LEFT_BRACKET expression RIGHT_BRACKET		{ $$ = createLn($3); }
	| COS LEFT_BRACKET expression RIGHT_BRACKET		{ $$ = createCos($3); }
	| SIN LEFT_BRACKET expression RIGHT_BRACKET		{ $$ = createSin($3); }
	| LOG LEFT_BRACKET expression RIGHT_BRACKET		{ $$ = createLog($3); }

	// Variables and Constants 
	| PHI											{ $$ = createPhi(); }
	| THETA											{ $$ = createTheta(); }
	| CONSTANT										{ $$ = createDecimal($1); }
	;

%%